export function downloadFile(url, name) {
  const fileExt = url.split('.').pop();
  if (!name.endsWith(fileExt)) {
    name = `${name}.${fileExt}`;
  }

  fetch(url)
    .then(resp => resp.blob())
    .then(blob => {
      const url = window.URL.createObjectURL(blob);
      const a = document.createElement('a');
      a.style.display = 'none';
      a.href = url;
      a.download = name;
      document.body.appendChild(a);
      a.click();
      window.URL.revokeObjectURL(url);
      document.body.removeChild(a);
  });
}